package com.jdrx.sw.sewage.api.app;

import com.jdrx.platform.common.support.gateway.GwConstants;
import com.jdrx.platform.commons.rest.beans.vo.ResponseVO;
import com.jdrx.platform.commons.rest.beans.vo.ResposeVO;
import com.jdrx.platform.commons.rest.exception.BizException;
import com.jdrx.platform.commons.rest.factory.ResponseFactory;
import com.jdrx.platform.commons.rest.factory.ResponseFactory2;
import com.jdrx.sw.sewage.beans.dto.AlarmQueryDTO;
import com.jdrx.sw.sewage.beans.vo.GISStationInfoAppVO;
import com.jdrx.sw.sewage.beans.vo.StationNameVO;
import com.jdrx.sw.sewage.common.constant.Constant;
import com.jdrx.sw.sewage.service.AlarmServiceImpl;
import com.jdrx.sw.sewage.service.StationServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/api/app/stationgis")
@Api(value = "app-厂站管理-GIS")
public class StationGISAppApi {

    @Autowired
    private StationServiceImpl stationServiceImpl;
    @Autowired
    private AlarmServiceImpl alarmServiceImpl;

    @ApiOperation(value = "查询当前登陆人责任得站点名称")
    @RequestMapping(value = "selectStationNameList", method = RequestMethod.POST)
    public ResponseVO<List<StationNameVO>> selectStationNameList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                                                 @RequestHeader(Constant.TENANT_ID) String tenantId,
                                                                 @RequestBody List<Long> dutyUserStationIds) {
        return ResponseFactory2.ok(stationServiceImpl.selectStationNameList(dutyUserStationIds));
    }

    @ApiOperation(value = "GIS站点列表查询")
    @RequestMapping(value = "selectGisStationList", method = RequestMethod.POST)
    public ResposeVO selectGisStationList(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                                          @RequestBody List<Long> dutyUserStationIds) {
        return ResponseFactory.ok(stationServiceImpl.selectGisStationList(dutyUserStationIds, dataNode));
    }

    @ApiOperation(value = "GIS站点详情信息查询")
    @RequestMapping(value = "selectGisStationInfo", method = RequestMethod.GET)
    public ResposeVO selectGisStationInfo(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                          @RequestHeader(Constant.TENANT_ID) String tenantId,
                                          @RequestParam Long stationId) throws BizException {
        return ResponseFactory.ok(stationServiceImpl.selectGisStationInfo(stationId));
    }

    @ApiOperation(value = "GIS站点详情信息查询（new）", response = GISStationInfoAppVO.class)
    @RequestMapping(value = "selectGisStationInfoNew", method = RequestMethod.GET)
    public ResposeVO selectGisStationInfoNew(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                             @RequestHeader(Constant.TENANT_ID) String tenantId,
                                             @RequestHeader(GwConstants.TRANSPARENT_USERID_FEILD) Long uid,
                                             @RequestParam Long stationId) throws BizException {
        return ResponseFactory.ok(stationServiceImpl.selectGisStationInfoApp(stationId, uid));
    }

    @ApiOperation(value = "告警分页查询")
    @RequestMapping(value = "selectAlarmByPage", method = RequestMethod.POST)
    public ResposeVO selectByPage(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                  @RequestHeader(Constant.TENANT_ID) String tenantId,
                                  @RequestBody AlarmQueryDTO alarmQueryDTO) {
        return ResponseFactory.ok(alarmServiceImpl.selectAlarmByPage(alarmQueryDTO));
    }

    @ApiOperation(value = "未读告警数 & 处理中告警数 &已完成告警数 & 未读和处理中告警数")
    @RequestMapping(value = "selectAllAlarmNum", method = RequestMethod.POST)
    public ResposeVO selectAllAlarmNum(@RequestHeader(Constant.DATA_NODE) String dataNode,
                                       @RequestHeader(Constant.TENANT_ID) String tenantId,
                                       @RequestBody List<Long> stationIds) throws BizException {
        return ResponseFactory.ok(alarmServiceImpl.selectAllAlarmNum(stationIds, null));
    }
}
